public class wxudong {

    private static Integer Josephus(Integer total, Integer key) {

	Boolean[] people = new Boolean[total];
        for (int i = 0; i < total; i++) {
            people[i] = true;
        }

        int peopleLeft = total;
        int count = 0;
        int index = 0;

        while (peopleLeft > 1) {
            if (people[index]) {
                count++;
 
                if (count == key) {
                    count = 0;
                    people[index] = false; 
                    peopleLeft--;
                }
            }
            index++;

            if (index == total) {
                index = 0;
            }
        }

        for (int j = 0; j < total; j++) {
            if (people[j]) {
                return j + 1;
            }
        }
        return null;
    }

    public static void main(String args[]) {
        int total = 10000;
        int key = 100;
        Integer lastOne = Josephus(total, key);
        System.out.println(total + "个人围成一圈，数到" + key + "的被淘汰，最后剩下的是第" + lastOne + "个人。");
    }
}
